winsafe\ole\com_interfaces/
istorage.rs

1#![allow(non_camel_case_types, non_snake_case)]
2
3use crate::co;
4use crate::decl::*;
5use crate::kernel::privs::*;
6use crate::ole::{privs::*, vts::*};
7use crate::prelude::*;
8
9com_interface! { IStorage: "0000000b-0000-0000-c000-000000000046";
10	/// [`IStorage`](https://learn.microsoft.com/en-us/windows/win32/api/objidl/nn-objidl-istorage)
11	/// COM interface.
12	///
13	/// Automatically calls
14	/// [`Release`](https://learn.microsoft.com/en-us/windows/win32/api/unknwn/nf-unknwn-iunknown-release)
15	/// when the object goes out of scope.
16}
17
18impl ole_IStorage for IStorage {}
19
20/// This trait is enabled with the `ole` feature, and provides methods for
21/// [`IStorage`](crate::IStorage).
22///
23/// Prefer importing this trait through the prelude:
24///
25/// ```no_run
26/// use winsafe::prelude::*;
27/// ```
28pub trait ole_IStorage: ole_IUnknown {
29	/// [`IStorage::Commit`](https://learn.microsoft.com/en-us/windows/win32/api/objidl/nf-objidl-istorage-commit)
30	/// method.
31	fn Commit(&self, commit_flags: co::STGC) -> HrResult<()> {
32		ok_to_hrresult(unsafe { (vt::<IStorageVT>(self).Commit)(self.ptr(), commit_flags.raw()) })
33	}
34
35	/// [`IStorage::CopyTo`](https://learn.microsoft.com/en-us/windows/win32/api/objidl/nf-objidl-istorage-copyto)
36	/// method.
37	fn CopyTo(
38		&self,
39		iid_exclude: &[co::IID],
40		snb_exclude: &[impl AsRef<str>],
41		stg_dest: &impl ole_IStorage,
42	) -> HrResult<()> {
43		ok_to_hrresult(unsafe {
44			(vt::<IStorageVT>(self).CopyTo)(
45				self.ptr(),
46				iid_exclude.len() as _,
47				vec_ptr(iid_exclude) as _,
48				SNB::from_strs(snb_exclude)?.as_ptr(),
49				stg_dest.ptr(),
50			)
51		})
52	}
53
54	/// [`IStorage::CreateStorage`](https://learn.microsoft.com/en-us/windows/win32/api/objidl/nf-objidl-istorage-createstorage)
55	/// method.
56	#[must_use]
57	fn CreateStorage(&self, name: &str, grf_mode: co::STGM) -> HrResult<IStorage> {
58		let mut queried = unsafe { IStorage::null() };
59		ok_to_hrresult(unsafe {
60			(vt::<IStorageVT>(self).CreateStorage)(
61				self.ptr(),
62				WString::from_str(name).as_ptr(),
63				grf_mode.raw(),
64				0,
65				0,
66				queried.as_mut(),
67			)
68		})
69		.map(|_| queried)
70	}
71
72	/// [`IStorage::CreateStream`](https://learn.microsoft.com/en-us/windows/win32/api/objidl/nf-objidl-istorage-createstream)
73	/// method.
74	#[must_use]
75	fn CreateStream(&self, name: &str, grf_mode: co::STGM) -> HrResult<IStream> {
76		let mut queried = unsafe { IStream::null() };
77		ok_to_hrresult(unsafe {
78			(vt::<IStorageVT>(self).CreateStream)(
79				self.ptr(),
80				WString::from_str(name).as_ptr(),
81				grf_mode.raw(),
82				0,
83				0,
84				queried.as_mut(),
85			)
86		})
87		.map(|_| queried)
88	}
89
90	/// [`IStorage::DestroyElement`](https://learn.microsoft.com/en-us/windows/win32/api/objidl/nf-objidl-istorage-destroyelement)
91	/// method.
92	fn DestroyElement(&self, name: &str) -> HrResult<()> {
93		ok_to_hrresult(unsafe {
94			(vt::<IStorageVT>(self).DestroyElement)(self.ptr(), WString::from_str(name).as_ptr())
95		})
96	}
97
98	/// [`IStorage::MoveElementTo`](https://learn.microsoft.com/en-us/windows/win32/api/objidl/nf-objidl-istorage-moveelementto)
99	/// method.
100	fn MoveElementTo(
101		&self,
102		name: &str,
103		stg_dest: &impl ole_IStorage,
104		new_name: &str,
105		grf_flags: co::STGMOVE,
106	) -> HrResult<()> {
107		ok_to_hrresult(unsafe {
108			(vt::<IStorageVT>(self).MoveElementTo)(
109				self.ptr(),
110				WString::from_str(name).as_ptr(),
111				stg_dest.ptr(),
112				WString::from_str(new_name).as_ptr(),
113				grf_flags.raw(),
114			)
115		})
116	}
117
118	/// [`IStorage::OpenStorage`](https://learn.microsoft.com/en-us/windows/win32/api/objidl/nf-objidl-istorage-openstorage)
119	/// method.
120	#[must_use]
121	fn OpenStorage(&self, name: &str, grf_mode: co::STGM) -> HrResult<IStorage> {
122		let mut queried = unsafe { IStorage::null() };
123		ok_to_hrresult(unsafe {
124			(vt::<IStorageVT>(self).OpenStorage)(
125				self.ptr(),
126				WString::from_str(name).as_ptr(),
127				std::ptr::null_mut(),
128				grf_mode.raw(),
129				std::ptr::null_mut(),
130				0,
131				queried.as_mut(),
132			)
133		})
134		.map(|_| queried)
135	}
136
137	/// [`IStorage::OpenStream`](https://learn.microsoft.com/en-us/windows/win32/api/objidl/nf-objidl-istorage-openstream)
138	/// method.
139	#[must_use]
140	fn OpenStream(&self, name: &str, grf_mode: co::STGM) -> HrResult<IStream> {
141		let mut queried = unsafe { IStream::null() };
142		ok_to_hrresult(unsafe {
143			(vt::<IStorageVT>(self).OpenStream)(
144				self.ptr(),
145				WString::from_str(name).as_ptr(),
146				std::ptr::null_mut(),
147				grf_mode.raw(),
148				0,
149				queried.as_mut(),
150			)
151		})
152		.map(|_| queried)
153	}
154
155	/// [`IStorage::RenameElement`](https://learn.microsoft.com/en-us/windows/win32/api/objidl/nf-objidl-istorage-renameelement)
156	/// method.
157	fn RenameElement(&self, old_name: &str, new_name: &str) -> HrResult<()> {
158		ok_to_hrresult(unsafe {
159			(vt::<IStorageVT>(self).RenameElement)(
160				self.ptr(),
161				WString::from_str(old_name).as_ptr(),
162				WString::from_str(new_name).as_ptr(),
163			)
164		})
165	}
166
167	fn_com_noparm! { Revert: IStorageVT;
168		/// [`IStorage::Revert`](https://learn.microsoft.com/en-us/windows/win32/api/objidl/nf-objidl-istorage-revert)
169		/// method.
170	}
171
172	/// [`IStorage::SetClass`](https://learn.microsoft.com/en-us/windows/win32/api/objidl/nf-objidl-istorage-setclass)
173	/// method.
174	fn SetClass(&self, clsid: &co::CLSID) -> HrResult<()> {
175		ok_to_hrresult(unsafe { (vt::<IStorageVT>(self).SetClass)(self.ptr(), pcvoid(clsid)) })
176	}
177
178	/// [`IStorage::SetElementTimes`](https://learn.microsoft.com/en-us/windows/win32/api/objidl/nf-objidl-istorage-setelementtimes)
179	/// method.
180	fn SetElementTimes(
181		&self,
182		name: Option<&str>,
183		creation: Option<&FILETIME>,
184		access: Option<&FILETIME>,
185		modification: Option<&FILETIME>,
186	) -> HrResult<()> {
187		ok_to_hrresult(unsafe {
188			(vt::<IStorageVT>(self).SetElementTimes)(
189				self.ptr(),
190				WString::from_opt_str(name).as_ptr(),
191				pcvoid_or_null(creation),
192				pcvoid_or_null(access),
193				pcvoid_or_null(modification),
194			)
195		})
196	}
197
198	/// [`IStorage::SetStateBits`](https://learn.microsoft.com/en-us/windows/win32/api/objidl/nf-objidl-istorage-setstatebits)
199	/// method.
200	fn SetStateBits(&self, state_bits: u32, mask: u32) -> HrResult<()> {
201		ok_to_hrresult(unsafe {
202			(vt::<IStorageVT>(self).SetStateBits)(self.ptr(), state_bits, mask)
203		})
204	}
205}